import axios from 'axios'

import { BASE_URL, TIMEOUT } from './config'

const instence = axios.create({
  baseURL: BASE_URL,
  timeout: TIMEOUT
})

instence.interceptors.request.use(config => {
  return config
}, err => {
  return err
})

instence.interceptors.response.use(res => {
  return res.data
}, err => {
  if(err && err.response) {
    switch(err.response.status) {
      case 400:
        console.log('请求错误')
        break
      case 401:
        console.log('请求错误')
        break
      default:
        console.log('err')
    }
  }
  return err
})

export default instence